<template>
	<view class="index">
		<muscihead title="网易云音乐" :showIcon="true"></muscihead>
		<view class="container">
			<scroll-view scroll-y>
				<!-- 顶部歌曲搜索区域 -->
				<view class="index-search" @tap="handleToSearch">
					<text class="iconfont icon-fangdajing"></text>
					<input type="text" placeholder="搜索歌曲" />
				</view>
				<!-- 骨架屏 -->
				<view class="skeleton" v-if="isLoading">
					<m-for-skeleton
						:avatarSize="200"
						:row="3"
						:title="false"
						:loading="isLoading"
						isarc="square"
						:titleStyle="{}"
						v-for="(item, key) in 4"
						:key="key"
					>
					</m-for-skeleton>
				</view>
				<!-- 歌曲列表区域 -->
				<view class="index-list" v-else>
					<view class="index-list-item" v-for="(item, index) in topList" :key="index" @tap="handleToList(item.id)">
						<!-- 左侧图片 -->
						<view class="index-list-img">
							<image :src="item.coverImgUrl"></image>
							<text>{{ item.updateFrequency }}</text>
						</view>
						<!-- 右侧歌曲 -->
						<view class="index-list-text">
							<view v-for="(song, index2) in item.tracks" :key="index2">
								{{ index2 + 1 }}.{{ song.first }} - {{ song.second }}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
import muscihead from '../../components/muscihead/muscihead.vue'

import { topList } from '../../common/api.js'
export default {
	data() {
		return {
			topList: [],
			isLoading: true,
		}
	},
	components: {
		muscihead
	},
	async onLoad() {
		const res = await topList()
		// console.log(res)
		if (res.length) {
			setTimeout(() => this.isLoading = false, 500)
			this.topList = res
		}
	},
	methods: {
		handleToList(listId) {
			uni.navigateTo({
				url: '/pages/list/list?listId=' + listId
			})
		},
		handleToSearch() {
			uni.navigateTo({
				url: '../search/search'
			})
		}
	}
}
</script>

<style scoped lang="less">
.index {
	.index-search {
		display: flex;
		align-items: center;
		height: 70rpx;
		margin: 70rpx 30rpx 30rpx;
		background-color: #f7f7f7;
		border-radius: 50rpx;
		text {
			font-size: 26rpx;
			margin-right: 26rpx;
			margin-left: 28rpx;
		}
		input {
			flex: 1;
			font-size: 28rpx;
		}
	}

	.index-list {
		margin: 0 30rpx;
		.index-list-item {
			display: flex;
			margin-bottom: 34rpx;
		}
		.index-list-img {
			position: relative;
			width: 212rpx;
			height: 212rpx;
			border-radius: 30rpx;
			overflow: hidden;
			margin-right: 22rpx;
			image {
				width: 100%;
				height: 100%;
			}
			text {
				position: absolute;
				left: 12rpx;
				bottom: 16rpx;
				color: #fff;
				font-size: 20rpx;
			}
		}
		.index-list-text {
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			font-size: 24rpx;
		}
	}
}
</style>
